package com.nowcoder.community.util;

import com.nowcoder.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * <p>Title: HostHolder</p>
 * <p>author 12427</p>
 *
 * @version ver1.0
 * @date 2022/7/22 16:29
 */

/**
 * 持有用户的信息，用于代替Session对象
 * 线程隔离
 */
@Component
public class HostHolder {
    private ThreadLocal<User> users = new ThreadLocal<>() ;

    public void setUser(User user){
        users.set(user);
    }

    public User getUser(){
        return users.get() ;
    }

    public void clear(){
        users.remove();
    }

}
